<template>
  <div class="password">
    <el-form ref="modifForm" :model="passWordForm" :rules="formRule">
      <el-form-item label="手机号码" prop="accountNumber">
        <el-input v-model.trim="passWordForm.accountNumber" placeholder="请输入手机号"></el-input>
      </el-form-item>
      <el-row type="flex" justify="space-between">
        <el-col :span="15">
          <el-form-item label="验证码" prop="verification">
            <el-input v-model.trim="passWordForm.verification" placeholder="请输入验证码"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-button
            :class="{'disabled':isDisable}"
            @click="getVerification"
            type="primary"
            :disabled="isDisable"
          >{{VerificationInfo}}</el-button>
        </el-col>
      </el-row>
    </el-form>
    <el-button @click="formValidate('modifForm',forgetOne)">下一步</el-button>
    <div class="link-box">
      <router-link to="/login">返回</router-link>
    </div>
  </div>
</template>
<script>
import mixin from "@/utils/mixin.js";
export default {
  data() {
    return {
      passWordForm: {
        accountNumber: "18381768975",
        passWord: "",
        verification: "",
      },
      formRule: {
        accountNumber: [
          { required: true, message: "请输入手机号码", trigger: "blur" },
          {
            min: 11,
            max: 11,
            message: "请输入正确的手机号码",
            trigger: "blur",
          },
        ],
        verification: [
          { required: true, message: "请输入验证码", trigger: "blur" },
        ],
      },
      ref: "modifForm",
    };
  },
  mixins: [mixin],
  methods: {
    // 获取验证码
    getVerification() {
      if (!/^1[3456789]\d{9}$/.test(this.passWordForm.accountNumber))
        return this.$message.error("请输入正确的手机号码");
      this.isDisable = true;
      this.$http(
        `/trademark/front/message/appointMsg/${this.passWordForm.accountNumber}`
      ).then(
        ({ data: res }) => {
          if (res.code !== 200) {
            this.isDisable = false;
            return ;
          }
          this.$message.success("验证码发送成功");
          this.VerificationTime();
        },
        (err) => {
          this.isDisable = false;
//          this.$message.error("网络错误");
        }
      );
    },
    //找回密码第一步
    forgetOne() {
      this.$http("/trademark/front/forget", {
        params: {
          phoneNum: this.passWordForm.accountNumber,
          inputCode: this.passWordForm.verification,
        },
      }).then(
        ({ data: res }) => {
          if (res.code !== 200) return ;
          this.$store.commit("setPhoneNumber", this.passWordForm.accountNumber);
          this.$router.push("/login/modify/edit");
        },
        (err) => {
//          this.$message.error("网络错误");
        }
      );
    },
  },
  created() {
    document.addEventListener("keydown", this.keydown);
  },
  beforeDestroy() {
    document.removeEventListener("keydown", this.keydown);
  },
};
</script>
<style lang="less" scoped>
.password {
  .welcome {
    font-size: 2em;
    font-weight: bold;
    line-height: 2em;
    text-align: center;
  }
  .el-form {
    margin-top: 1rem;
    /deep/.el-form-item__label {
      line-height: 1rem;
    }
    /deep/.el-input__inner {
      height: 2.5rem;
    }
    .el-button {
      margin-top: 20px;
      font-size: 1em;
      border: none;
    }
    .disabled {
      background-color: #999;
    }
  }
  .el-button {
    width: 100%;
    height: 2.5rem;
    background-color: #013d87;
    color: #fff;
    margin-top: 2rem;
    font-size: 1.2em;
  }
  .link-box {
    text-align: center;
    padding-top: 0.5em;
  }
  a {
    color: #666666;
  }
}
</style>